package com.sentrix.auto.printercenter.presentation.center;

import com.mybatisflex.core.paginate.Page;
import com.sentrix.auto.printercenter.application.StationService;
import com.sentrix.auto.printercenter.presentation.center.dto.PrinterTaskPageQueryReqDto;
import com.sentrix.auto.printercenter.presentation.center.dto.StationAddReqDto;
import com.sentrix.auto.printercenter.presentation.center.dto.StationPageQueryReqDto;
import com.sentrix.auto.printercenter.presentation.center.dto.StationResDto;
import com.sentrix.auto.printercenter.presentation.common.BaseResponse;
import com.sentrix.auto.printercenter.presentation.common.DataResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 打印中心工作站管理
 */
@Tag(name = "工作站管理", description = "工作站管理")
@RestController
@RequestMapping("station")
public class StationPrinterController {

    @Resource
    private StationService stationService;


    @Operation(summary = "工作站添加或修改")
    @PostMapping("addOrEdit")
    public BaseResponse add(@RequestBody StationAddReqDto stationAdd) {
        stationService.addOrEdit(stationAdd);
        return new BaseResponse();
    }

    @Operation(summary = "工作站删除")
    @Parameter(name = "stationCode", required = true, description = "工作站编码")
    @GetMapping("{stationCode}/remove")
    public BaseResponse remove(@PathVariable(name = "stationCode") String stationCode) {
        stationService.remove(stationCode);
        return new BaseResponse();
    }

    @Operation(summary = "工作站列表")
    @GetMapping("list")
    public DataResponse<List<StationResDto>> list() {
        List<StationResDto> stationResDtos = stationService.listAll();
        return new DataResponse<>(stationResDtos);
    }

    @Operation(summary = "工作站分页查询")
    @PostMapping("page")
    public DataResponse<Page<StationResDto>> page(@Validated @RequestBody StationPageQueryReqDto param) {
        Page<StationResDto> page = stationService.page(param, StationResDto::fromDomain);
        return new DataResponse<>(page);
    }

    @Operation(summary = "工作站详情查询")
    @Parameter(name = "stationCode", required = true, description = "工作站编码")
    @GetMapping("{stationCode}/query")
    public DataResponse<StationResDto> query(@PathVariable(name = "stationCode") String stationCode) {
        StationResDto stationResDto = stationService.findByCode(stationCode, StationResDto::fromDomain);
        return new DataResponse<>(stationResDto);
    }
}
